package com.ogawa.joypal.user.dialog

import android.content.Context
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import com.ogawa.joypal.user.R


class ChangeNameDialog {
    interface ChangeNameDialogListener{
        fun successOnclick(newName:String)
    }
    fun show(context: Context, oldName: String?, callback: ChangeNameDialogListener) {
        val alertDialog =
            AlertDialog.Builder(context, R.style.BaseDialog).create()
        val view = LayoutInflater.from(context)
            .inflate(R.layout.dialog_userinfo_edit_rename, null)
        val inputEt =
            view.findViewById<EditText>(R.id.inputEt)
        view.findViewById<TextView>(R.id.cancelButton).setOnClickListener { alertDialog.dismiss() }
        view.findViewById<TextView>(R.id.saveBt).setOnClickListener {
            alertDialog.dismiss()
            callback.successOnclick(inputEt.text.toString())
        }
        inputEt.setText(oldName)
        alertDialog.setView(view)
        alertDialog.show()
    }
}